﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.TimeSheetSign
{
    public class TimeSheetSignPresenter: Presenter<ITimeSheetSignView>
    {
        public TimeSheetSignPresenter(ITimeSheetSignView view)
            : base(view)
        {
        }

        public void Display(string timeSheetSignId)
        {
            if (timeSheetSignId == null) return;

            var timeSheetSign = Model.GetTimeSheetSign(timeSheetSignId);

            View.TimeSheetSignID = timeSheetSign.TimeSheetSignID;
            View.TimeSheetSignCode = timeSheetSign.TimeSheetSignCode;
            View.TimeSheetSignName = timeSheetSign.TimeSheetSignName;
            View.SalaryRate = timeSheetSign.SalaryRate;
            View.Description = timeSheetSign.Description;
            View.IsActive = timeSheetSign.IsActive;
        }

        public int Save()
        {
            var TimeSheetSign = new TimeSheetSignModel
            {
                TimeSheetSignID = View.TimeSheetSignID,
                TimeSheetSignCode = View.TimeSheetSignCode,
                TimeSheetSignName = View.TimeSheetSignName,
                SalaryRate = View.SalaryRate,
                Description = View.Description,
                IsActive = View.IsActive
            };

            if (View.TimeSheetSignID == null)
                return Model.AddTimeSheetSign(TimeSheetSign);
            else
                return Model.UpdateTimeSheetSign(TimeSheetSign);
        }

        public int Delete(string timeSheetSignId)
        {
            return Model.DeleteTimeSheetSign(timeSheetSignId);
        }
    }
}
